<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title></title>
</head>
<body>
	<div>January(1),February(2),March(3),April(4),May(5),June(6),July(7),Aguest(8),September(9),October(10),November(11),December(12)</div>
	<input value="删除January(1)" type="button">
	<hr/>

	<div>0,1,2,3,4,5,6,7,8,9</div>
	<input value="复制" type="button">
	<input value="还原" type="button">
	<hr/>
	<div>red,green,blue,white,yellow,black,brown</div>
	<input value="删除前三项" type="button">
</body>
<script type="text/javascript">
	window.onload = function (){

		var tempArr = [];//定义一个临时
		var bs1 = bs2 = true;
		//获取div数组
		var divArr = document.getElementsByTagName("div");
		console.log("我得到一个div数组"+divArr);
		//获取input数组
		var inputArr = document.getElementsByTagName("input");
		console.log("我得到一个div数组"+inputArr);
		
		//添加或者删除第一个元素
		inputArr[0].onclick = function(){
			tempArr = strConvertArray(divArr[0].innerHTML);
			bs1?(tempArr.shift(),this.value = this.value.replace("删除","添加"),bs1 = false):(tempArr.unshift("January(1)"),this.value = this.value.replace("添加","删除"),bs1 = true);
			divArr[0].innerHTML = tempArr.join();
		}
		
		//复制
		inputArr[1].onclick = function(){
			tempArr = strConvertArray(divArr[1].innerHTML);
			divArr[1].innerHTML = tempArr.concat(tempArr);
		}
		
		//还原
		inputArr[2].onclick = function(){
			tempArr = strConvertArray(divArr[1].innerHTML);
			alert(tempArr.length);
			tempArr.length = 10;
			divArr[1].innerHTML = tempArr.join();//join():将数组转化为字符串
		}
		
		//删除前三项
		inputArr[3].onclick = function(){
			tempArr = strConvertArray(divArr[2].innerHTML);
			tempArr.splice(0,3);//该方法会改变原始数组。
			divArr[2].innerHTML = tempArr.join();
		}
		//工具函数:将一个字符串转化为数组
		function strConvertArray(str){
			tempArr.length = 0;//将数组置空
			str = str.split(",");
			return str;
		}
	}
</script>
</html>